﻿package com.vinyl.utils 
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import com.adobe.serialization.json.JSON;
	import flash.net.*;
	import flash.net.URLRequest;
    import flash.net.URLLoader;
	
	/**
	 * ...
	 * @author vi-nyl
	 */
	public class JsonToObject extends EventDispatcher
	{
		private var loader:URLLoader = new URLLoader() ;
		private var request:URLRequest = new URLRequest() ;
		
		public var data;
		
		public function JsonToObject( url )
		{
			request.url = url ;
			loader.load(request) ;
			loader.addEventListener( Event.COMPLETE, decodeJSON ) ;
		}
		
		private function decodeJSON(event:Event):void 
		{
			var loader:URLLoader = URLLoader(event.target) ;
			data = JSON.decode(loader.data) ;
			
			dispatchEvent( new Event( Event.COMPLETE ) );
		}
	}
}